﻿
Partial Class Paginas_InscribirUnEvento
    Inherits System.Web.UI.Page

#Region "Declaracion de Funciones y Procedimientos de pagina"
    Private Sub CargarInfoEvento()
        Dim objNegEven As New dllNegocio.NegEventos(System.Configuration.ConfigurationManager.AppSettings.Get("SPECBDD"))
        Dim myCollect As Collection
        Dim objEven As New dllEntidades.clsEventos
        Try
            myCollect = objNegEven.ListarEventos(Me.hdnIdEvento.Value.Trim, "", 0)
            If myCollect.Count > 0 Then
                objEven = myCollect.Item(1)
                Me.hdnCodImagen.Value = objEven.CodigoLugar.ToString.Trim
                Me.lblEvento.Text = objEven.Nombre
                Me.lblFecHoraIni.Text = objEven.FechaHoraInicioPublicacion.ToString
                Me.lblFecHoraFin.Text = objEven.FechaHoraFinPublicacion.ToString
                Me.lblLugar.Text = objEven.Lugar
                Me.hdnImagen.Value = objEven.ImagenMailEvento
                If objEven.CodigoTipoAsistente = 3 Then
                    Me.ddlNumAsis.Items.Insert(0, New ListItem("5", 5))
                    Me.ddlNumAsis.Items.Insert(0, New ListItem("4", 4))
                    Me.ddlNumAsis.Items.Insert(0, New ListItem("3", 3))
                    Me.ddlNumAsis.Items.Insert(0, New ListItem("2", 2))
                ElseIf objEven.CodigoTipoAsistente = 1 Then
                    Me.ddlNumAsis.Items.Insert(0, New ListItem("1", 1))
                ElseIf objEven.CodigoTipoAsistente = 2 Then
                    Me.ddlNumAsis.Items.Insert(0, New ListItem("2", 2))
                End If
            End If
        Catch ex As Exception
        Finally
            objNegEven.Dispose()
            objNegEven = Nothing
            myCollect = Nothing
            objEven.Dispose()
            objEven = Nothing
        End Try
    End Sub

#End Region

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Me.hdnIdEvento.Value = Request.QueryString("EventoID")
            Call CargarInfoEvento()
        End If
    End Sub

    Protected Sub btnVolver_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVolver.Click
        Response.Redirect("InscribirEvento.aspx?PostBack=SI")
        Response.End()
    End Sub

    Protected Sub btnInscribir_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInscribir.Click
        Dim objNegEven As New dllNegocio.NegEventos(System.Configuration.ConfigurationManager.AppSettings.Get("SPECBDD"))
        Dim myCollect As Collection
        Dim objEven As New dllEntidades.clsEventos
        Dim objFunc As New dllEntidades.clsFuncionario
        Dim rutaImg As String = Server.MapPath("~")
        rutaImg = rutaImg & IIf(Right(rutaImg.ToString.Trim, 1) = "\", "", "\") & "Paginas\Img\ImgLoad\Eventos\" & Me.hdnImagen.Value.Trim
        Dim objServidor As New dllNegocio.NegMail()

        Try
            objServidor.CorreoDesde = System.Configuration.ConfigurationManager.AppSettings.Get("CorreoDesde")
            objServidor.ServidorMail = System.Configuration.ConfigurationManager.AppSettings.Get("ServidorMail")
            objEven.Codigo = Me.hdnIdEvento.Value.Trim
            objFunc.Rut = Session("RutUsuario")
            If objNegEven.InscribirEvento(objEven, objFunc, rutaImg, objServidor, Me.ddlNumAsis.SelectedItem.Value.Trim) = True Then
                Dim myPagina As String = "CuponEvento.aspx?EventoID=" & Me.hdnIdEvento.Value.Trim & "&CantAsis=" & Me.ddlNumAsis.SelectedItem.Value.Trim
                UtilidadesPagina.EjecutaScript("AbrirPopup('" & myPagina & "');", Me.Page)
            End If
        Catch ex As Exception
        Finally
            objNegEven.Dispose()
            objNegEven = Nothing
            myCollect = Nothing
            objEven.Dispose()
            objEven = Nothing
            objServidor.Dispose()
            objServidor = Nothing
        End Try
    End Sub
End Class
